#!/opt/python-2.5/bin/python2.5

bgcolor = "333366"
text = "FFFFCC"
font = "Verdana"

import cgi, cgitb, os
cgitb.enable()
print "Content-type: text/html;charset=utf-8"
print 
print "<body bgcolor=%s text=%s>" % (bgcolor, text)
quesform = cgi.FieldStorage()
quesfile = "tempdir/question.file"
if "Question" in quesform.keys():
	question = quesform["Question"].value
	file = open(quesfile, 'w')
	file.write(question + "\n")
	file.close()
if "Restart" in quesform.keys():
	try:
		os.remove(quesfile)
	except:
		print "I'm sorry, but something is preventing me from resetting the posed question."
try:
	## The file exists, becuase we have a question already therein.
	file = open(quesfile, 'r')
	question = file.readline()
	if not question:	raise IOError
	file.close()
	print "<font face=%s size=5><center>" % font
	print "The question at hand: <i><b>"
	print question + "</b></i>"
	print "<form name=\"Resetter\">"
	print "<input type=hidden name=\"Restart\" value=\"start over\"/>"
	print "<button type=submit name=\"Redo\">New question</button></form>"
	print "</center></font>"
except (IOError):
	## The file doesn't exist, because no one has typed in a question.
	print "<font face=%s size=3><b>Please enter the burning question here:\t</b></font>" % font
	print "<form name=\"Query Form\" method=post>"
	print "<input name=\"Question\" type=text size=70 maxlength=255 autocomplete />"
	print "<button type=reset name=\"Clear\">Erase this...</button>\t"
	print "<button type=submit name=\"Submit\">Start game!</button>"
	print "</form></body>"
